package JasPerl::TagExt::Tag;

use strict;
use warnings;

sub import {
    no strict qw(refs);

    my $class = shift;
    return unless @_;

    my $name = shift;
    my $caller = caller;
    ${"${caller}::TAGS"}{$name} = $class;
}

sub new {
    my $class = shift;
    bless { }, $class;
}

sub get_parent {
    return $_[0]->{parent};
}

sub set_parent {
    $_[0]->{parent} = $_[1];
}

sub find_ancestor_isa {
    my ($self, $class) = @_;
    for ($self = $self->get_parent(); $self; $self = $self->get_parent()) {
        return $self if $self->isa($class);
    }
    return $self;
}

sub find_ancestor_can {
    my ($self, $method) = @_;
    for ($self = $self->get_parent(); $self; $self = $self->get_parent()) {
        return $self if $self->can($method);
    }
    return $self;
}

sub do_tag {
    # default tag processing does nothing
}

1;
